<?php
$con = mysql_connect("localhost", "root", "yourpassword");
if( !$con )
{
  die('Could not connect: ' . mysql_error());
}
// select database
mysql_select_db("celsus", $con);

// 21012
echo "Checking database to 21012<br/>";
if(false === mysql_query("select notify from description_status limit 0"))
  mysql_query("ALTER TABLE description_status ADD notify text NOT NULL default ''", $con);

// 21013
echo "Chekcing database to 21013<br/>";
if(false === mysql_query("select id from external_ill limit 0"))
  mysql_query("CREATE TABLE external_ill (id int unsigned NOT NULL primary key,email varchar(128) NOT NULL default '',sent int NOT NULL default '0')", $con );

// 21020
echo "Checking database to 21020<br/>";
if(false === mysql_query("select send_ill from description_status limit 0"))
  mysql_query("ALTER TABLE description_status ADD send_ill SMALLINT(5) NOT NULL", $con);

// 21025
echo "Checking database to 21025<br/>";
if(false === mysql_query("select version from database_version limit 0"))
{
  if(mysql_query("CREATE TABLE database_version (version INT(10) NOT NULL default '0')", $con))
    mysql_query("INSERT INTO database_version (version) VALUES (21025)", $con );
}
if(false === mysql_query("select external_id from requests limit 0"))
  mysql_query("ALTER TABLE requests ADD external_id INT(10) NOT NULL", $con);

// 21029
echo "Checking database to 21029<br/>";
mysql_query("UPDATE database_version SET version=21029", $con);
if(false === mysql_query("select library_id_origin from requests limit 0"))
  mysql_query("ALTER TABLE requests ADD library_id_origin SMALLINT(5) NOT NULL default 0", $con);
if(false === mysql_query("select external from description_user_type limit 0"))
  mysql_query("ALTER TABLE description_user_type ADD external smallint NOT NULL default '0'", $con);

// 21033
echo "Checking database to 21033<br/>";
mysql_query("UPDATE database_version SET version=21033", $con);
if(false === mysql_query("select notes from users limit 0"))
  mysql_query("ALTER TABLE users ADD notes TEXT default '')", $con);
if(false === mysql_query("select external_id from users limit 0"))
  mysql_query("ALTER TABLE users ADD external_id INT(10) NOT NULL default '0'", $con);
if(false === mysql_query("select complete from description_status limit 0"))
  mysql_query("ALTER TABLE description_status ADD complete SMALLINT(5) NOT NULL default '0'", $con);
if(false === mysql_query("select default_collection from staff limit 0"))
  mysql_query("ALTER TABLE staff ADD default_collection INT NOT NULL default '-1'", $con);

// 21035
echo "Checking database to 21035<br/>";
mysql_query("UPDATE database_version SET version=21035", $con);
if(false === mysql_query("select explanation from description_ill limit 0"))
  mysql_query("ALTER TABLE description_ill ADD explanation varchar(256) NOT NULL default '', ADD user_listed smallint unsigned NOT NULL default '1'", $con);
if(false === mysql_query("select company from external_ill limit 0"))
  mysql_query("ALTER TABLE external_ill ADD company varchar(128) NOT NULL default '', ADD date_join datetime NOT NULL default '0000-00-00',
               ADD date_out datetime NOT NULL default '0000-00-00'", $con);
if(false === mysql_query("select staff_id from external_ill_history limit 0"))
  mysql_query("CREATE TABLE external_ill_history (staff_id int unsigned NOT NULL default 0, user_id int unsigned NOT NULL primary key,
               ill_user_id int unsigned NOT NULL default 0, date_out datetime NOT NULL default '0000-00-00', description varchar(256) default '',
               link text default '')", $con);

// 21037
echo "Checking database to 21037<br/>";
mysql_query("UPDATE database_version SET version=21037", $con);
if(false === mysql_query("select icon_file from description_collection limit 0"))
  mysql_query("ALTER TABLE description_collection ADD icon_file varchar(256) NOT NULL default ''", $con);
if(false === mysql_query("select id from request_links limit 0"))
  mysql_query("CREATE TABLE request_links (id int unsigned NOT NULL auto_increment primary key, staff_id int unsigned NOT NULL default 0,
               date_in datetime NOT NULL default '0000-00-00', uid varchar(128) default '', title varchar(255) default '', source varchar(255) default '',
               link text default '')", $con);

// 21038
echo "Checking database to 21038<br/>";
mysql_query("UPDATE database_version SET version=21038", $con);
if(false === mysql_query("select information from description_status limit 0"))
  mysql_query("ALTER TABLE description_status ADD information TEXT NOT NULL default ''", $con);

// 21042
echo "Checking database to 21042<br/>";
mysql_query("UPDATE database_version SET version=21042", $con);
if(false === mysql_query("select id from source_links limit 0"))
  mysql_query("CREATE TABLE source_links (id int unsigned NOT NULL auto_increment primary key, staff_id int unsigned NOT NULL default 0,
               date_in datetime NOT NULL default '0000-00-00', title varchar(255) default '', link text default '')", $con);

// 21044
echo "Checking database to 21044<br/>";
mysql_query("UPDATE database_version SET version=21044", $con);
if(false === mysql_query("select default_ill_library from staff limit 0"))
  mysql_query("ALTER TABLE staff ADD default_ill_library INT NOT NULL default '-1'", $con);

// 21046
echo "Checking database to 21046<br/>";
mysql_query("UPDATE database_version SET version=21046", $con);
if(false === mysql_query("select notes from source_links limit 0"))
  mysql_query("ALTER TABLE source_links ADD notes TEXT NOT NULL", $con);
if(false === mysql_query("select material from source_links limit 0"))
  mysql_query("ALTER TABLE source_links ADD material SMALLINT NOT NULL DEFAULT 0");
if(false === mysql_query("select notes from request_links limit 0"))
  mysql_query("ALTER TABLE request_links ADD notes TEXT NOT NULL", $con);
if(false === mysql_query("select material from request_links limit 0"))
  mysql_query("ALTER TABLE request_links ADD material SMALLINT NOT NULL DEFAULT 0");

// 21047
echo "Checking database to 21047<br/>";
mysql_query("UPDATE database_version SET version=21047", $con);
if(false === mysql_query("select message_file from description_method limit 0"))
  mysql_query("ALTER TABLE description_method ADD message_file varchar(255) default ''", $con);

// 21048
echo "Checking database to 21048<br/>";
mysql_query("UPDATE database_version SET version=21048", $con);
if(false === mysql_query("select message_subject from description_method limit 0"))
  mysql_query("ALTER TABLE description_method ADD message_subject varchar(255) default ''", $con);

// 21059
echo "Checking database to 21059<br/>";
mysql_query("UPDATE database_version SET version=21059", $con);
if(false === mysql_query("select message_subject from description_ill limit 0"))
  mysql_query("ALTER TABLE description_ill ADD message_subject varchar(255) default ''", $con);
if(false === mysql_query("select subject from description_status limit 0"))
  mysql_query("ALTER TABLE description_status ADD subject varchar(255) default ''", $con);

// 21060
echo "Checking database to 21060<br/>";
mysql_query("UPDATE database_version SET version=21060", $con);
if(false === mysql_query("select print_notice from description_collection limit 0"))
  mysql_query("ALTER TABLE description_collection ADD print_notice varchar(255) default ''", $con);

// 21063
echo "Chekcing database to 21063<br/>";
mysql_query("UPDATE database_version SET version=21063", $con);
if(false === mysql_query("select id from information limit 0"))
  mysql_query("CREATE TABLE information (id int unsigned NOT NULL primary key, type int NOT NULL default 0, html text NOT NULL default '')", $con );

// 21064
echo "Checking database to 21064<br/>";
mysql_query("UPDATE database_version SET version=21064", $con);
if(false === mysql_query("select message_file from description_status limit 0"))
  mysql_query("ALTER TABLE description_status ADD message_file varchar(255) default ''", $con);
if(false === mysql_query("select message_file_ext from description_status limit 0"))
  mysql_query("ALTER TABLE description_status ADD message_file_ext varchar(255) default ''", $con);
if(false === mysql_query("select location from requests limit 0"))
  mysql_query("ALTER TABLE requests ADD location varchar(255) default ''", $con);
if(false === mysql_query("select link from requests limit 0"))
  mysql_query("ALTER TABLE requests ADD link varchar(2048) default ''", $con);
if(false === mysql_query("select user_listed from requests limit 0"))
  mysql_query("ALTER TABLE information ADD user_listed tinyint(4) NOT NULL default '0'", $con);
if(false === mysql_query("select information from description_library limit 0"))
  mysql_query("ALTER TABLE description_library ADD information varchar(1024) default ''", $con);
if(false === mysql_query("select diverted from description_library limit 0"))
  mysql_query("ALTER TABLE description_library ADD diverted tinyint(4) NOT NULL default '0'", $con);
if(false === mysql_query("select retain from requests limit 0"))
  mysql_query("ALTER TABLE requests ADD retain tinyint(4) NOT NULL default '0'", $con);

echo "Database updated";
?>
